package com.example.leave;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class LeaveRequestPage {
    private JFrame frame;
    private JTable table;
    private DefaultTableModel tableModel;

    public LeaveRequestPage(List<LeaveRequest> leaveRequests) {
        frame = new JFrame("请假记录");
        frame.setLayout(new BorderLayout());

        // 表格列名
        String[] columnNames = {"学号", "开始时间", "结束时间", "原因", "状态"};

        // 创建表格模型
        tableModel = new DefaultTableModel(columnNames, 0);

        // 创建表格并设置模型
        table = new JTable(tableModel);
        JScrollPane scrollPane = new JScrollPane(table);
        frame.add(scrollPane, BorderLayout.CENTER);

        // 添加数据到表格模型
        for (LeaveRequest request : leaveRequests) {
            tableModel.addRow(new Object[]{
                request.getStudentId(),
                request.getStartTime(),
                request.getEndTime(),
                request.getReason(),
                request.getStatus()
            });
        }

        // 设置窗口属性
        frame.setSize(600, 400);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

// 请假记录类
class LeaveRequest {
    private String studentId;
    private String startTime;
    private String endTime;
    private String reason;
    private String status;

    public LeaveRequest(String studentId, String startTime, String endTime, String reason, String status) {
        this.studentId = studentId;
        this.startTime = startTime;
        this.endTime = endTime;
        this.reason = reason;
        this.status = status;
    }

    // Getter方法
    public String getStudentId() { return studentId; }
    public String getStartTime() { return startTime; }
    public String getEndTime() { return endTime; }
    public String getReason() { return reason; }
    public String getStatus() { return status; }
}

